import React from "react";

import './index.css';

class HelloWorld extends React.Component {
    static defaultProps = {
        title: '默认的Title',
    }

    state = {
        count: 0,
    }

    componentDidMount() {
        this.timerId = setInterval(() => {
            this.setState({
                count: this.state.count + 1,
            });
        }, 1000);
    }

    componentWillUnmount() {
        clearInterval(this.timerId);
    }

    render() {
        return (
            <div className="hello-world">
                <h2>{this.props.title}~~{this.state.count}</h2>
            </div>
        )
    }
}

export default HelloWorld;